package com.itheima.controller;

import com.itheima.R;
import com.itheima.dto.MenuDTO;
import com.itheima.service.SysMenuService;
import com.itheima.vo.MenuVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys_menu")
@RequiredArgsConstructor
public class MenuController {
    private final SysMenuService sysMenuService;

    /**
     * 所有菜单
     * @return
     */
    @GetMapping("/allData")
    public R<List<MenuVO>> allData(){
        List<MenuVO> menuVOList = sysMenuService.allData();
        return R.success(menuVOList);
    }

    /**
     * 菜单添加
     * @param menuDTO
     * @return
     */
    @PostMapping("/add")
    public R<?> save(@RequestBody MenuDTO menuDTO){
        sysMenuService.save(menuDTO);
        return R.success();
    }

    /**
     * 删除菜单
     * @param id
     * @return
     */
    @GetMapping("/del")
    public R<?> deleteById(Integer id){
        sysMenuService.delete(id);
        return R.success();
    }

    /**
     * 查询回显/菜单详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public R<MenuVO> rowInfo(Integer id){
        MenuVO menuVO = sysMenuService.rowInfo(id);
        return R.success(menuVO);
    }
    @PostMapping("/update")
    public R<?> update(@RequestBody MenuDTO menuDTO){
        sysMenuService.update(menuDTO);
        return R.success();
    }

}
